<template>
<div class="bottom-bar">
  <div class="check-content">
    <check-button :is-checked="isSelectAll"
                  class="check-button"
                  @click.native="checkClick"></check-button>
    <span>全选</span>
  </div>

  <div class="totalPrice" >
    合计{{totalPrice}}
  </div>
  <div class="calculate">
    去计算:({{checkLength}})
  </div>
</div>
</template>

<script>
import CheckButton from "components/content/CheckButton/CheckButton";
import {mapGetters} from "vuex";

export default {
  name: "CartBottomBar",
  components:{
    CheckButton
  },
  computed:{
    ...mapGetters(['cartList']),
    totalPrice(){
      return "￥"+this.cartList.filter( item =>{
        return item.checked
      }).reduce((preValue,item)=> {
        return preValue+ item.price * item.count
      },0)
    },
    checkLength(){
      return this.cartList.filter(item => item.checked).length
    },
    isSelectAll(){
     // return  !(this.cartList.filter(item => !item.checked).length)
    if (this.cartList.length === 0) return  false
      return !this.cartList.find(item =>!item.checked)
    }
  },
  methods:{
    checkClick(){
      if (this.isSelectAll){  //全选
        this.cartList.forEach(item =>item.checked = false)
      }else {  //部分或全部不选中
        this.cartList.forEach(item =>item.checked = true)
      }

      // this.cartList.forEach(item => item.checked =!this.isSelectAll)
    }
  }
}
</script>

<style scoped>
.bottom-bar {
  background-color: #eeeeee;
  display: flex;
  height: 40px;
  position: absolute;
  bottom: 49px;
  left: 0;
  right: 0;
  line-height: 40px;
}

.check-content{
  display: flex;
  align-items: center;
  margin-left: 10px;

}
.check-button {
  width: 20px;
  height: 20px;
  line-height: 20px;
  margin-right: 10px;
}

.totalPrice{
  margin-left: 30px;
  font-size: 14px;
  flex: 1;
}
.calculate{
  background-color: var(--color-high-text);
  width: 90px;
  text-align: center;
  font-weight: bolder;
  color: #eeeeee;

}
</style>